home *** CD-ROM | disk | FTP | other *** search
- /* chmod.c, from page 351 of Turbo C Bible */
- #include<stdio.h>
- #include<sys\types.h>
- #include<sys\stat.h>
- #include<io.h>
- main (int argc, char **argv)
- {
- int pmode = -999;
- if (argc < 3)
- {
- printf (
- "Usage: %s <pathname> <R|W>\n", argv [0]);
- }
- else
- {
- /* Convert last argument to permission code */
- if (argv [2] [0] == 'R') pmode = S_IREAD;
- if (argv [2] [0] == 'W') pmode = S_IREAD|S_IWRITE;
- if (pmode == -999)
- {
- printf ("Unknown permission: %s\n", argv [2]);
- exit (1);
- }
- if (chmod (argv [1], pmode) == -1)
- {
- perror ("Error in \"chmod\"");
- }
- }
- }